package main

import (
	"fmt"
	"time"
)

func timeBase() {
	now := time.Now()
	fmt.Println(now)        // 对象，打印时显示为字符串
	fmt.Println(now.Date()) // 年月日
	fmt.Println(now.Year())
	fmt.Println(now.Month()) // 月份为英文
	fmt.Println(now.Day())
	fmt.Println(now.Weekday()) // 星期为英文
	fmt.Println(now.Hour())
	fmt.Println(now.Minute())
	fmt.Println(now.Second())

	fmt.Println(now.Unix())
	fmt.Println(now.UnixNano())
	ret := 1595690686
	fmt.Println(time.Unix(int64(ret), 0))
}

func timeMethods() {
	now := time.Now()
	fmt.Println(now.Add(24 * time.Hour))
}

func timeFormat() {
	now := time.Now()
	fmt.Println(now.Format("2006年01月02日 03:04:05 PM"))

	// time.ParseInLocation()
	// time.Sleep()
	// timeObj, err := time.Parse("2006/01/02 15:04:05", "2019/08/04 14:15:20")
}

func setTimer() {
	// 定时器的间隔设置为1s
	timer := time.Tick(time.Second)
	// 此时的t是当前的时间
	for t := range timer {
		fmt.Println(t)
	}
}

func main() {
	timeBase()
	timeMethods()
	timeFormat()
	// setTimer()
}
